<?php

class Institution_selection extends CI_Controller {

    var $user_id;

    function __construct() {
        parent::__construct();

//        if(!$this->session->userdata('user_id')){
//            $uri = site_url('visitor/home');
//            echo "<script>javascript:alert('Please Login to Your Account'); window.location = '" . $uri . "'</script>";
//            exit;
//        }
        $this->user_id = 1;


        //Set folder to load view (under View for)
        $this->layouts->set_view_folder('institution_selection');

        //Load model
        $this->load->model('institution_selection_model');
        $this->load->model('register_model');

        //load js and css
        $this->layouts->set_css('datatable/demo_table');
        $this->layouts->set_css('datatable/smoothness/jquery-ui-1.8.4.custom');
        $this->layouts->set_js('jquery.dataTables');
        $this->layouts->set_js('js_institutionselection/institution');

        //Send base url to view for processing
        $this->view_data['base_url'] = base_url();
        $this->view_data['country_list'] = $this->register_model->country_list();
    }

    function index() {
        $this->layouts->view('institution_content', $this->view_data);
    }

    // search bar dropdown list based on search category
    function selectlist($countryID, $institutionList) {
        $this->view_data['select_list'] = $this->institution_selection_model->getSelectionList($institutionList, $countryID);
        echo $this->load->view('institution_selection/institution_dropdown_list', $this->view_data, true);
    }

    // display the search result
    function searchResult2() {
        $this->view_data['search_list'] = $this->institution_selection_model->getSearchResult();
        $this->layouts->view('institution_result_view', $this->view_data);
    }

    function selInstitution() {
        $query = $this->institution_selection_model->selInstitutionModel($this->user_id);
        if ($query === true) {
            echo "Successfully";
        }
    }

    function confirmSelection() {
        $this->load->model('institution_selection_model');
        $ids = $this->input->post('institution_id');
        foreach ($ids as $id) {
            $this->institution_selection_model->confirmSelectionModel($id);
        }
        redirect('institution_selection');
    }

    function showDesc($institution_id) {
        $this->load->model('institution_selection_model');
        $data['desc'] = $this->institution_selection_model->showDesc($institution_id);
        $this->load->view('institution_selection/institution_desc', $data);
    }

    function courseIns() {
        $this->view_data['courseIns_list'] = $this->institution_selection_model->courseInsModel($this->user_id);
        $this->layouts->view('course_institution', $this->view_data);
    }

    function my_institution() {
        $query = $this->institution_selection_model->my_institutionModel($this->user_id);
        $this->view_data['my_institution'] = $query['query'];
        $this->layouts->view('my_institution', $this->view_data);
    }

    function rmv_institution() {
        $query = $this->institution_selection_model->rmv_insModel($this->user_id);
        if ($query) {
            echo "Remove Successfully";
        }
    }

    function ins_course($id) {
        $this->view_data['course_list'] = $this->institution_selection_model->ins_courseModel($id);
        echo $this->load->view('institution_selection/institution_course_list', $this->view_data, true);
    }

}

?>
